package com.huawei.appgallery.forum.posts.card;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.GradientDrawable;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.posts.view.CountDownLayout;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.fastengine.fastview.download.utils.PackageUtils;
import huawei.widget.HwButton;
import java.lang.ref.WeakReference;
import o.bzd.a;
import o.bzd.e;
import o.bzd.j;
import o.bzt;
import o.cgz;
import o.chy;
import o.dof;
import o.epw;
import o.eqx;
import o.eqz;
import o.evx;
import o.fu;

public class ForumProcuctCard extends ForumCard {
    private long ʻ;
    private ImageView ʼ;
    private TextView ʽ;
    protected HwButton ˊ;
    private boolean ˊॱ = false;
    ForumProductBean ˋ = new ForumProductBean();
    private int ˋॱ;
    protected TextView ˎ;
    protected CountDownLayout ˏ;
    protected TextView ॱ;
    private ConstraintLayout ॱॱ;
    private b ᐝ;

    public static class b extends CountDownTimer {
        private ForumProductBean ˋ;
        private WeakReference<TextView> ˏ;
        private WeakReference<CountDownLayout> ॱ;

        public b(long j, long j2, CountDownLayout countDownLayout, TextView textView, ForumProductBean forumProductBean) {
            super(j, j2);
            this.ॱ = new WeakReference(countDownLayout);
            this.ˏ = new WeakReference(textView);
            this.ˋ = forumProductBean;
        }

        public void onTick(long j) {
            CountDownLayout countDownLayout = (CountDownLayout) this.ॱ.get();
            if (countDownLayout != null) {
                countDownLayout.setPromoteTime(j);
            }
        }

        public void onFinish() {
            CountDownLayout countDownLayout = (CountDownLayout) this.ॱ.get();
            TextView textView = (TextView) this.ˏ.get();
            if (countDownLayout != null) {
                countDownLayout.setVisibility(8);
            }
            if (textView != null) {
                textView.setText(this.ˋ.ᐝ());
            }
        }
    }

    public void ˊ(boolean z) {
        this.ˊॱ = z;
    }

    public ForumProcuctCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ॱॱ = (ConstraintLayout) view.findViewById(o.bzd.b.ˏˏ);
        this.ʼ = (ImageView) view.findViewById(o.bzd.b.ॱʻ);
        this.ʽ = (TextView) view.findViewById(o.bzd.b.ॱͺ);
        this.ॱ = (TextView) view.findViewById(o.bzd.b.ॱʽ);
        this.ˎ = (TextView) view.findViewById(o.bzd.b.ـ);
        this.ˏ = (CountDownLayout) view.findViewById(o.bzd.b.ˑ);
        this.ˊ = (HwButton) view.findViewById(o.bzd.b.ॱʼ);
        if (this.ˊॱ || epw.ˏ()) {
            this.ˊ.setBackground(this.ʼॱ.getDrawable(e.ˎ));
        }
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumProductBean) {
            this.ˋ = (ForumProductBean) cardBean;
            ˊ(this.ˋ.ˊ());
            this.ʽ.setText(this.ˋ.ʽ());
            CharSequence ʼ = this.ˋ.ʼ();
            if (TextUtils.isEmpty(ʼ)) {
                this.ॱ.setVisibility(8);
            } else {
                this.ॱ.setVisibility(0);
                this.ॱ.setText(ʼ);
            }
            this.ʻ = this.ˋ.ˏॱ() - System.currentTimeMillis();
            ˊ(this.ˋ);
        }
    }

    private void ˊ(String str) {
        if (!TextUtils.isEmpty(str)) {
            eqx.ॱ(this.ʼॱ, this.ˋ.ˊ(), new eqz(this) {
                final /* synthetic */ ForumProcuctCard ॱ;

                {
                    this.ॱ = r1;
                }

                public void ॱ(Bitmap bitmap) {
                    if (bitmap != null) {
                        this.ॱ.ʼ.setImageBitmap(bitmap);
                        this.ॱ.ˊ(bzt.ˊ(bitmap, PackageUtils.HWGAMEBOX_PACKAGE_NAME));
                    }
                }
            });
        }
    }

    private void ˊ(ForumProductBean forumProductBean) {
        if (forumProductBean.ͺ() == 1) {
            ॱ(forumProductBean, true);
        } else if (forumProductBean.ͺ() == 2) {
            this.ˎ.setText(this.ʼॱ.getResources().getString(j.ʽॱ));
        } else {
            ॱ(forumProductBean, false);
        }
    }

    private void ॱ(ForumProductBean forumProductBean, boolean z) {
        if (forumProductBean.ˊॱ() > 0 || forumProductBean.ˊॱ() == -1) {
            this.ˋॱ = ˎ(forumProductBean, z);
            if (z) {
                ˏ(forumProductBean);
                return;
            } else {
                ॱ(forumProductBean);
                return;
            }
        }
        this.ˎ.setText(this.ʼॱ.getResources().getString(j.ʾ));
    }

    private int ˎ(ForumProductBean forumProductBean, boolean z) {
        if (!z && dof.ˋ(forumProductBean.ˋॱ())) {
            return 0;
        }
        long ˏॱ = forumProductBean.ˏॱ();
        if (ˏॱ <= 0) {
            return 3;
        }
        if (ˏॱ - System.currentTimeMillis() > 0) {
            return 1;
        }
        return 2;
    }

    private void ˏ(ForumProductBean forumProductBean) {
        if (this.ˋॱ == 2) {
            this.ˎ.setText(forumProductBean.ᐝ());
            return;
        }
        this.ˎ.setText(this.ʼॱ.getResources().getString(j.ʻॱ));
        if (this.ˋॱ == 1) {
            this.ˏ.setVisibility(0);
            this.ˏ.setPromoteTime(this.ʻ);
            ॱ(this.ʻ, forumProductBean);
        }
    }

    private void ॱ(ForumProductBean forumProductBean) {
        if (this.ˋॱ == 0 || this.ˋॱ == 2) {
            this.ˎ.setText(forumProductBean.ᐝ());
            return;
        }
        this.ˎ.setText(forumProductBean.ˋॱ());
        if (this.ˋॱ == 1) {
            this.ˏ.setVisibility(0);
            this.ˏ.setPromoteTime(this.ʻ);
            ॱ(this.ʻ, forumProductBean);
        }
    }

    private void ॱ(long j, ForumProductBean forumProductBean) {
        if (this.ᐝ != null) {
            this.ᐝ.cancel();
        }
        this.ᐝ = new b(100 + j, 1000, this.ˏ, this.ˎ, forumProductBean);
        this.ᐝ.start();
    }

    private void ˊ(@ColorInt int i) {
        int ˋ = ˋ(i);
        int ˎ = ˎ(i);
        GradientDrawable gradientDrawable = (GradientDrawable) this.ॱॱ.getBackground();
        gradientDrawable.setColor(ˋ);
        this.ॱॱ.setBackground(gradientDrawable);
        gradientDrawable = (GradientDrawable) this.ˏ.ˎ.getBackground();
        gradientDrawable.setColor(ˎ);
        this.ˏ.ˎ.setBackground(gradientDrawable);
        this.ˏ.ॱ.setBackground(gradientDrawable);
        this.ˏ.ˏ.setBackground(gradientDrawable);
        this.ˏ.ˋ.setBackground(gradientDrawable);
        this.ˏ.ˊ.setTextColor(ˎ);
        this.ˏ.ʼ.setTextColor(ˎ);
        this.ˏ.ॱॱ.setTextColor(ˎ);
        this.ˊ.setTextColor(ˎ);
    }

    @ColorInt
    private int ˋ(@ColorInt int i) {
        if (this.ˊॱ) {
            return ˏ(i);
        }
        if (epw.ˏ()) {
            return ˏ(i);
        }
        return ॱ(i);
    }

    @ColorInt
    private int ˎ(@ColorInt int i) {
        return ʼ(i);
    }

    @ColorInt
    private int ॱ(@ColorInt int i) {
        if (i == -1) {
            return this.ʼॱ.getResources().getColor(a.ॱˋ);
        }
        float ॱॱ = ॱॱ(i);
        if (16.0f <= ॱॱ && ॱॱ < 61.0f) {
            return this.ʼॱ.getResources().getColor(a.ॱˋ);
        }
        if (61.0f <= ॱॱ && ॱॱ < 181.0f) {
            return this.ʼॱ.getResources().getColor(a.ॱˊ);
        }
        if (181.0f <= ॱॱ && ॱॱ < 246.0f) {
            return this.ʼॱ.getResources().getColor(a.ʻ);
        }
        if (246.0f > ॱॱ || ॱॱ >= 321.0f) {
            return this.ʼॱ.getResources().getColor(a.ॱˎ);
        }
        return this.ʼॱ.getResources().getColor(a.ᐝॱ);
    }

    @ColorInt
    private int ˏ(@ColorInt int i) {
        if (i == -1) {
            return this.ʼॱ.getResources().getColor(a.ˋॱ);
        }
        float ॱॱ = ॱॱ(i);
        if (16.0f <= ॱॱ && ॱॱ < 61.0f) {
            return this.ʼॱ.getResources().getColor(a.ˋॱ);
        }
        if (61.0f <= ॱॱ && ॱॱ < 181.0f) {
            return this.ʼॱ.getResources().getColor(a.ͺ);
        }
        if (181.0f <= ॱॱ && ॱॱ < 246.0f) {
            return this.ʼॱ.getResources().getColor(a.ᐝ);
        }
        if (246.0f > ॱॱ || ॱॱ >= 321.0f) {
            return this.ʼॱ.getResources().getColor(a.ˏॱ);
        }
        return this.ʼॱ.getResources().getColor(a.ˊॱ);
    }

    @ColorInt
    private int ʼ(@ColorInt int i) {
        if (i == -1) {
            return this.ʼॱ.getResources().getColor(a.ʿ);
        }
        float ॱॱ = ॱॱ(i);
        if (16.0f <= ॱॱ && ॱॱ < 61.0f) {
            return this.ʼॱ.getResources().getColor(a.ʿ);
        }
        if (61.0f <= ॱॱ && ॱॱ < 181.0f) {
            return this.ʼॱ.getResources().getColor(a.ॱᐝ);
        }
        if (181.0f <= ॱॱ && ॱॱ < 246.0f) {
            return this.ʼॱ.getResources().getColor(a.ʻॱ);
        }
        if (246.0f > ॱॱ || ॱॱ >= 321.0f) {
            return this.ʼॱ.getResources().getColor(a.ʼॱ);
        }
        return this.ʼॱ.getResources().getColor(a.ʽॱ);
    }

    private float ॱॱ(@ColorInt int i) {
        float[] fArr = new float[3];
        fu.ॱ(i, fArr);
        return fArr[0];
    }

    public void ॱ(final chy o_chy) {
        View ˉ = ˉ();
        if (ˉ != null) {
            OnClickListener anonymousClass2 = new evx(this) {
                final /* synthetic */ ForumProcuctCard ˊ;

                public void ˋ(View view) {
                    if (o_chy != null) {
                        o_chy.ˏ(0, this.ˊ);
                    }
                }
            };
            ˉ.setOnClickListener(anonymousClass2);
            this.ˊ.setOnClickListener(anonymousClass2);
        }
    }
}
